#include "WritingScore.h"

WritingScore::WritingScore(void)
{
}

WritingScore::WritingScore(ReadHighscores read1, Highscore* newScore)
{
	read = read1;

	Highscore** h = read.GetHighscores();
	for(int i = 0; i < 10; i++){
		a[i] = h[i];
	}
	a[10] = newScore;

	selectionSort();

	ofstream myFile;
	myFile.open("res/highscores.txt");
	myFile << "Time:Deaths:Points\n";
	for(int i = 0; i < 10; i++){
		myFile << a[i]->time << ":" << a[i]->deaths <<  ":" << a[i]->points << "\n";
	}
	myFile.close();

}

WritingScore::~WritingScore(void)
{
}
//sorting the scores places the highest scores first
void WritingScore::selectionSort()
	{
		int i,j,mpos;
		Highscore* aux;
		for(i=0;i<10;i++)
			{
				mpos=i;
				for(j=i+1;j<=10;j++)
				{
					if((a[j]->getScore()) > (a[mpos]->getScore()))
						mpos=j;
				}
				if(mpos!=i)
				{
						aux=a[i];
						a[i]=a[mpos];
						a[mpos]=aux;
				}
			}
	}
